package net.huosen.blog.action;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import net.huosen.blog.model.Article;
import net.huosen.blog.service.IArticleService;

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.opensymphony.xwork2.ActionSupport;

/**
 * @descript 文章管理Action
 * @author huozhicheng@gmail.com
 * @date 2014-1-9下午9:33:04
 */
@Scope("prototype")
@Component("articleAction")
public class ArticleAction extends ActionSupport{

	private static final long serialVersionUID = -6901084896162868214L;
	private static final Logger log = LogManager.getLogger(ArticleAction.class.getSimpleName());
	private Article article = new Article();
	private List<Article> list = new ArrayList<Article>();
	
	@Resource(name="articleService")
	private IArticleService articleService;

	public String getArticleList(){
		log.debug("正在获取文章列表......");
		list = articleService.getList();
		return SUCCESS;
	}
	
	public String addArticle(){
		log.debug("正在发布新文章......");
		articleService.insert(article);
		return SUCCESS;
	}

	public List<Article> getList() {
		return list;
	}

	public void setList(List<Article> list) {
		this.list = list;
	}

	public Article getArticle() {
		return article;
	}

	public void setArticle(Article article) {
		this.article = article;
	}
	
}
